package com.xingdata.jjxc.base;

import java.util.HashMap;

import com.xingdata.jjxc.http.HttpUtil;

import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import android.widget.Toast;

/**
 * 根Activity
 * 
 * @author Administrator
 * 
 */
public abstract class BaseTabActivity extends TabActivity {
	protected ProgressDialog commonProgress = null;
	protected Handler mHandler;
	protected TabHost mTabHost;
	protected View tabContentView;
	/**
	 * 【HTTP请求】声明Http请求实例，并声明参数实例
	 */
	protected HttpUtil mHttpUtil = null;
	protected HashMap<String, String> paramsMap=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mHttpUtil=HttpUtil.getInstance(this);
	}


	/**
	 * 显示 ProgressDialog
	 */
	protected ProgressDialog showProgressDialog(String title, String message) {
		if (commonProgress != null && commonProgress.isShowing()) {
			commonProgress.dismiss();
		}
		commonProgress = ProgressDialog.show(this, title, message);
		commonProgress.setCancelable(false);
		commonProgress
				.setOnCancelListener(new DialogInterface.OnCancelListener() {

					@Override
					public void onCancel(DialogInterface dialog) {
						// TODO Auto-generated method stub
						// NetworkManager.shutdownHttpClit();
						// dismissProgressDialog();
						dialog.dismiss();
						// finish();
					}
				});
		return commonProgress;
	}

	/**
	 * 隐藏ProgressDialog
	 */
	protected void dismissProgressDialog() {
		if (commonProgress != null && commonProgress.isShowing()) {
			commonProgress.dismiss();
		}
	}

	/**
	 * 更新ProgressDialog提示消息
	 * 
	 * @param progressDialog
	 * @param title
	 * @param message
	 * @return
	 */
	protected ProgressDialog updataProgressDialog(
			ProgressDialog progressDialog, String strTitle, String strMessage) {
		String title = "";
		String message = "";
		if (progressDialog != null && progressDialog.isShowing()) {
			if (strTitle != null) {
				title = strTitle;
			}
			if (strMessage != null) {
				message = strMessage;
			}
			progressDialog.setTitle(title);
			progressDialog.setMessage(message);
		} else {
			showProgressDialog(title, message);
		}
		return progressDialog;

	}

	/**
	 * 初始化UI
	 */
	public abstract void initView();

	/**
	 * 初始化数据
	 */
	public abstract void initData();

	/**
	 * 提示（长）
	 * 
	 * @param text
	 */
	protected void showToastL(String text) {
		Toast.makeText(this, text, Toast.LENGTH_LONG).show();
	}

	/**
	 * 提示（短）
	 * 
	 * @param text
	 */
	protected void showToastS(String text) {
		Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		return super.onKeyDown(keyCode, event);
	}

}
